﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sbook.AdminIstrator
{
    public partial class DeleteAction : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["UId"] != null)
                {
                    string UId = Request.QueryString["UId"];
                    if (Business.DeliveryService.Delivery_GetByAll().FindAll(d => d.UId == UId).Count > 0)
                    {
                        Response.Write("<script>alert('User này đã có trong hóa đơn ,hãy xóa hóa đơn!'); window.location.href='/AdminIstrator/UserManagement.aspx';</script>");
                    }
                    else
                    {
                        Business.UserService.User_Delete(Request.QueryString["UId"]);
                        Response.Redirect("UserManagement.aspx");
                    }
                }
                else
                {
                    if (Request.QueryString["ProductId"] != null)
                    {
                        Business.DeliveryDetailService.DeliveryDetail_Delete(Request.QueryString["DeliveryId"], Request.QueryString["ProductId"]);
                        Response.Redirect("Delivery_Detail.aspx?DeliveryId=" + Request.QueryString["DeliveryId"]);
                    }
                    else
                    {
                        string DId = Request.QueryString["DeliveryId"];
                        if (Business.DeliveryDetailService.DeliveryDetail_GetByAll().FindAll(de => de.DeliveryId == DId).Count <= 0)
                        {
                            Business.DeliveryService.Delivery_DeleteById(Request.QueryString["DeliveryId"]);
                            Response.Redirect("ListDelivery.aspx");
                        }
                        else
                        {
                            Response.Write("<script>alert('User này đã có trong hóa đơn ,hãy xóa hóa đơn!'); window.location.href='/AdminIstrator/ListDelivery.aspx';</script>");
                        }
                    }
                }
            }
                

               
        }
    }
}